home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH2 / SRC / LINES.FRM < prev    next >
Text File  |  1996-04-30  |  5KB  |  175 lines

  1. VERSION 4.00
  2. Begin VB.Form LinesForm 
  3.    Caption         =   "Line vs. Polyline"
  4.    ClientHeight    =   4125
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1815
  7.    ClientWidth     =   6855
  8.    Height          =   4815
  9.    Left            =   1080
  10.    LinkTopic       =   "LineForm"
  11.    ScaleHeight     =   4125
  12.    ScaleWidth      =   6855
  13.    Top             =   1185
  14.    Width           =   6975
  15.    Begin VB.CommandButton Command1 
  16.       Caption         =   "Go"
  17.       Default         =   -1  'True
  18.       Height          =   375
  19.       Left            =   3120
  20.       TabIndex        =   4
  21.       Top             =   3720
  22.       Width           =   615
  23.    End
  24.    Begin VB.PictureBox Picture2 
  25.       AutoRedraw      =   -1  'True
  26.       Height          =   3375
  27.       Left            =   3480
  28.       ScaleHeight     =   221
  29.       ScaleMode       =   3  'Pixel
  30.       ScaleWidth      =   221
  31.       TabIndex        =   1
  32.       Top             =   240
  33.       Width           =   3375
  34.    End
  35.    Begin VB.PictureBox Picture1 
  36.       AutoRedraw      =   -1  'True
  37.       Height          =   3375
  38.       Left            =   0
  39.       ScaleHeight     =   221
  40.       ScaleMode       =   3  'Pixel
  41.       ScaleWidth      =   221
  42.       TabIndex        =   0
  43.       Top             =   240
  44.       Width           =   3375
  45.    End
  46.    Begin VB.Label Label3 
  47.       Alignment       =   2  'Center
  48.       Caption         =   "Line"
  49.       Height          =   255
  50.       Index           =   1
  51.       Left            =   3480
  52.       TabIndex        =   6
  53.       Top             =   0
  54.       Width           =   3375
  55.    End
  56.    Begin VB.Label Label3 
  57.       Alignment       =   2  'Center
  58.       Caption         =   "Polyline"
  59.       Height          =   255
  60.       Index           =   0
  61.       Left            =   0
  62.       TabIndex        =   5
  63.       Top             =   0
  64.       Width           =   3375
  65.    End
  66.    Begin VB.Label Label2 
  67.       BorderStyle     =   1  'Fixed Single
  68.       Height          =   255
  69.       Left            =   4560
  70.       TabIndex        =   3
  71.       Top             =   3720
  72.       Width           =   1215
  73.    End
  74.    Begin VB.Label Label1 
  75.       BorderStyle     =   1  'Fixed Single
  76.       Height          =   255
  77.       Left            =   1080
  78.       TabIndex        =   2
  79.       Top             =   3720
  80.       Width           =   1215
  81.    End
  82.    Begin VB.Menu mnuFile 
  83.       Caption         =   "&File"
  84.       Begin VB.Menu mnuFileExit 
  85.          Caption         =   "E&xit"
  86.       End
  87.    End
  88. End
  89. Attribute VB_Name = "LinesForm"
  90. Attribute VB_Creatable = False
  91. Attribute VB_Exposed = False
  92. Option Explicit
  93.  
  94. Dim Points() As POINTAPI
  95. Dim NumPoints As Integer
  96. Private Sub Command1_Click()
  97. Const NUM_TRIALS = 100
  98.  
  99. Dim start_time As Single
  100. Dim stop_time As Single
  101. Dim i As Integer
  102. Dim trial As Integer
  103.  
  104.     Picture1.Cls
  105.     Picture2.Cls
  106.     Label1.Caption = ""
  107.     Label2.Caption = ""
  108.     MousePointer = vbHourglass
  109.     DoEvents
  110.     
  111.     start_time = Timer()
  112.     For trial = 1 To NUM_TRIALS
  113.         If Polyline(Picture1.hdc, Points(1), NumPoints) = 0 Then Exit Sub
  114.     Next trial
  115.     stop_time = Timer()
  116.     Picture1.Refresh
  117.     Label1.Caption = Format$(stop_time - start_time, "0.0000")
  118.     DoEvents
  119.     
  120.     start_time = Timer()
  121.     For trial = 1 To NUM_TRIALS
  122.         Picture2.CurrentX = Points(1).x
  123.         Picture2.CurrentY = Points(1).y
  124.         For i = 2 To NumPoints
  125.             Picture2.Line -(Points(i).x, Points(i).y)
  126.         Next i
  127.     Next trial
  128.     stop_time = Timer()
  129.     Picture2.Refresh
  130.     Label2.Caption = Format$(stop_time - start_time, "0.0000")
  131.     
  132.     MousePointer = vbDefault
  133. End Sub
  134.  
  135. Private Sub Form_Load()
  136. Dim i As Integer
  137. Dim small As Boolean
  138. Dim half As Integer
  139. Dim hgt As Integer
  140. Dim wid As Integer
  141.  
  142.     NumPoints = Picture1.ScaleWidth
  143.     ReDim Points(1 To NumPoints)
  144.     half = NumPoints \ 2
  145.     
  146.     hgt = Picture1.ScaleHeight
  147.     For i = 1 To half
  148.         Points(i).x = 2 * i
  149.         If small Then
  150.             Points(i).y = 0
  151.         Else
  152.             Points(i).y = hgt
  153.         End If
  154.         small = Not small
  155.     Next i
  156.     
  157.     wid = Picture1.ScaleWidth
  158.     For i = half + 1 To NumPoints
  159.         Points(i).y = 2 * (i - half)
  160.         If small Then
  161.             Points(i).x = 0
  162.         Else
  163.             Points(i).x = wid
  164.         End If
  165.         small = Not small
  166.     Next i
  167. End Sub
  168.  
  169.  
  170. Private Sub mnuFileExit_Click()
  171.     Unload Me
  172. End Sub
  173.  
  174.  
  175.